/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entreprise;
import entreprise.Drug;
import java.sql.SQLException;
import mapping.DBDrug;
import java.util.List;
/**
 *
 * @author Quoc-Khai
 */
public class DrugService {
    public boolean createDrug(int drugID,String drugName, float drugPrice, String drugDescripton) throws SQLException{
        //check drug ton tai hay chua, goi ham getDrug(drugID) trong mapping
        //neu chua ton tai thi tao doi tuong drug, roi su dung ham createDrug(drug) trong mapping de luu
        DBDrug dbDrug = new DBDrug();
        Drug iDrug = new Drug();
        iDrug = dbDrug.getDrug(drugID);
        if (iDrug.getDrugID().length() <= 0) {
            iDrug.setDrugName(drugName);
            iDrug.setDrugPrice(drugPrice);
            iDrug.setDrugDescription(drugDescripton);
            
            dbDrug.createDrug(iDrug);
            return true;
        }
        
        System.out.println("Drug existe!");
        return false;
    }
    public boolean deleteDrug(int drugID) throws SQLException{
        //check drug ton tai hay chua-> neu chua thi dua ra thong bao
        //goi ham deleteDrug tai lop mapping de xoa drug trong database
        DBDrug dbDrug = new DBDrug();
        Drug iDrug = new Drug();
        iDrug = dbDrug.getDrug(drugID);
        if (iDrug.getDrugID().length() > 0) {
            dbDrug.deleteDrug(drugID);
            return true;
        }
        
        System.out.println("Drug not existe!");
        return false;
    }
    public boolean updateDrug(int drugID,String drugName, float drugPrice, String drugDescripton) throws SQLException{
        //check drug ton tai hay chua bang ham getDrug() trong mapping
        //neu tim thay, update thong tin cho drug nay, dung cac ham get, set trong lop drug
        //goi ham updateDrug() trong mapping de luu
        DBDrug dbDrug = new DBDrug();
        Drug iDrug = new Drug();
        iDrug = dbDrug.getDrug(drugID);
        if (iDrug.getDrugID().length() > 0) {
            iDrug.setDrugID(String.valueOf(drugID));
            iDrug.setDrugName(drugName);
            iDrug.setDrugPrice(drugPrice);
            iDrug.setDrugDescription(drugDescripton);
            
            dbDrug.updateDrug(iDrug);
            return true;
        }
        
        System.out.println("Drug not existe!");
        return false;
    }
    public List<Drug> findDrugs(String drugName){
        List<Drug> drugs=null;
        //chuan bi search condition
        //goi ham getDrugs trong mapping de tim
        return drugs;
    }
    public List<Drug> drugs(){
        List<Drug> drugs=null;
        //TODO
        return drugs;
    }
}
